package com.ts.api.http.platform.biz;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.algorithm.digest.MD5;
import com.gitee.apanlh.util.algorithm.encrypt.symmetric.AES;
import com.gitee.apanlh.util.base.*;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.common.util.H5DomainUrlUtils;
import com.ts.api.http.platform.entity.apply.ApiPlatApplyYiRongQianBao;
import com.ts.api.http.platform.entity.dataexchange.ApiPlatDataExchangeYiRongQianBao;
import com.ts.api.module.api.convert.core.annotation.ApiPlan;
import com.ts.api.module.api.convert.core.annotation.ApiPlanConvertType;
import com.ts.api.module.api.convert.core.entity.ApiApplyParameter;
import com.ts.api.module.api.convert.core.entity.ApiBizStatus;
import com.ts.api.module.api.convert.core.entity.ApiDataExchangeParameter;
import com.ts.api.module.api.convert.core.utils.ApiFieldConverter;
import com.ts.api.module.api.convert.platform.entity.*;
import com.ts.api.module.api.convert.platform.handler.ApiPlatformPhoneMd5ConvertHandler;
import com.ts.api.module.api.entity.ApiProtocol;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 安心分期-宜融钱包-全82 11位
 *  链接：https://apifox.com/apidoc/shared-3b364ecd-0bf3-4316-8869-98c51ee86c77
 *  密码：HWrSTqQZ
 *
 * @author gwc
 * @create 2025-08-14 下午2:08
 */

@ApiPlan(productId = "410", type = ApiPlanConvertType.PLAT_PHONE_MD5)
public class ApiPlatYiRongQianBaoPhoneMd5 implements ApiPlatformPhoneMd5ConvertHandler {

    private static final String KEY = "2516c6ee8281a65b9d476c211f89b292";
    private static final String CHANNEL_CODE = "XXASHNLPMI";

    @Override
    public Object dataExchange(ApiDataExchangeParameter apiDataExchangeParameter) throws Exception {
        // 创建对应撞库实体类
        ApiPlatDataExchangeYiRongQianBao yiRongQianBaoData = new ApiPlatDataExchangeYiRongQianBao();
        // 扩展
        ApiFieldConverter apiFieldConverter = ApiFieldConverter.create(apiDataExchangeParameter);
        // 手机号码 MD5
        yiRongQianBaoData.setPhone_md5(apiDataExchangeParameter.getPhoneMd5());
        // 年龄：0 未知
        yiRongQianBaoData.setAge(apiFieldConverter.getAgeInt());
        // 性别：0 未知；1 男；2 女
        Integer sex = ChooseEq.create()
                .when(apiDataExchangeParameter.getSex(), "0", 1)
                .when(apiDataExchangeParameter.getSex(), "1", 2)
                .when(apiDataExchangeParameter.getSex(), "2", 0)
                .end(0);
        yiRongQianBaoData.setGender(sex);
        // 用户 IP：0 未知；(例：144.144.144.144)
        if (ValidParam.isNotEmpty(apiDataExchangeParameter.getIp())) {
            yiRongQianBaoData.setIp(apiDataExchangeParameter.getIp());
        } else {
            yiRongQianBaoData.setIp("0");
        }
        // 城市名：0 未知；(例：成都市)
        yiRongQianBaoData.setAddress_name(apiDataExchangeParameter.getCity());
        // 学历：0 未知；1 本科以下；2 本科及以上
        Integer education = ChooseEq.create()
                .when(apiDataExchangeParameter.getEducationAttainment(), "1", 1)
                .when(apiDataExchangeParameter.getEducationAttainment(), "2", 1)
                .when(apiDataExchangeParameter.getEducationAttainment(), "3", 1)
                .when(apiDataExchangeParameter.getEducationAttainment(), "4", 1)
                .when(apiDataExchangeParameter.getEducationAttainment(), "5", 2)
                .when(apiDataExchangeParameter.getEducationAttainment(), "6", 2)
                .end(0);
        yiRongQianBaoData.setEducation(education);
        // 职业：0 未知；1 自由职业者；2 上班族；3 企业主/个体户；4 公务员/事业/国企
        Integer career = ChooseEq.create()
                .when(apiDataExchangeParameter.getCareer(), "1", 2)
                .when(apiDataExchangeParameter.getCareer(), "2", 1)
                .when(apiDataExchangeParameter.getCareer(), "3", 3)
                .when(apiDataExchangeParameter.getCareer(), "4", 4)
                .when(apiDataExchangeParameter.getCareer(), "5", 3)
                .end(0);
        yiRongQianBaoData.setVocation(career);
        // 信用：0 未知；1 一年内有逾期；2 一年内无逾期；3 从未逾期
        Integer overdue = ChooseEq.create()
                .when(apiDataExchangeParameter.getOverdue(), "1", 3)
                .when(apiDataExchangeParameter.getOverdue(), "2", 1)
                .when(apiDataExchangeParameter.getOverdue(), "3", 2)
                .end(0);
        yiRongQianBaoData.setCredit(overdue);
        // 贷款申请(近1月)：0 未知；1 3 次以上；2 3 次及以内；3 无申请贷款
        yiRongQianBaoData.setLoans(0);
        // 芝麻分：0 未知；1 无；2 600分及以下；3 600-650分；4 650-700分；5 700分以上
        Integer zhima = ChooseEq.create()
                .when(apiDataExchangeParameter.getSesameCredit(), "1", 2)
                .when(apiDataExchangeParameter.getSesameCredit(), "2", 3)
                .when(apiDataExchangeParameter.getSesameCredit(), "3", 4)
                .when(apiDataExchangeParameter.getSesameCredit(), "4", 5)
                .end(0);
        yiRongQianBaoData.setSesame(zhima);
        // 社保：0 未知；1 无本地社保；2 未满6个月；3 6个月及以上
        Integer socialSecurity = ChooseEq.create()
                .when(apiDataExchangeParameter.getSocialSecurity(), "1", 1)
                .when(apiDataExchangeParameter.getSocialSecurity(), "2", 2)
                .when(apiDataExchangeParameter.getSocialSecurity(), "3", 3)
                .when(apiDataExchangeParameter.getSocialSecurity(), "4", 2)
                .end(0);
        yiRongQianBaoData.setSocial(socialSecurity);
        // 公积金：0 未知；1 无本地公积金；2 未满6个月；3 6个月及以上
        Integer providentFund = ChooseEq.create()
                .when(apiDataExchangeParameter.getProvidentFund(), "1", 1)
                .when(apiDataExchangeParameter.getProvidentFund(), "2", 2)
                .when(apiDataExchangeParameter.getProvidentFund(), "3", 3)
                .when(apiDataExchangeParameter.getProvidentFund(), "4", 2)
                .end(0);
        yiRongQianBaoData.setGjj(providentFund);
        // 房产：0 未知；1 无；2 有异地房产；3 有本地房产
        Integer house = ChooseEq.create()
                .when(apiDataExchangeParameter.getRealEstateInfo(), "1", 1)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "2", 3)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "3", 3)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "4", 3)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "5", 3)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "6", 3)
                .end(0);
        yiRongQianBaoData.setRoom(house);
        // 车产：0 未知；1 无；2 有车不可抵押；3 有车可抵押
        Integer vehicle = ChooseEq.create()
                .when(apiDataExchangeParameter.getCarInfo(), "1", 1)
                .when(apiDataExchangeParameter.getCarInfo(), "2", 2)
                .when(apiDataExchangeParameter.getCarInfo(), "3", 3)
                .when(apiDataExchangeParameter.getCarInfo(), "4", 3)
                .end(0);
        yiRongQianBaoData.setCar(vehicle);
        // 保险保单：0 未知；1 无；2 缴纳未满1年；3 缴纳1年以上
        Integer commericalInsurance = ChooseEq.create()
                .when(apiDataExchangeParameter.getInsurancePolicy(), "1", 1)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "2", 2)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "3", 3)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "4", 2)
                .end(0);
        yiRongQianBaoData.setPolicy(commericalInsurance);
        // 信用卡：0 未知；1 无；2 1万元以下；3 1万元及以上
        Integer creditCard = ChooseEq.create()
                .when(apiDataExchangeParameter.getCreditLimit(), "1", 1)
                .when(apiDataExchangeParameter.getCreditLimit(), "2", 2)
                .when(apiDataExchangeParameter.getCreditLimit(), "3", 2)
                .when(apiDataExchangeParameter.getCreditLimit(), "4", 3)
                .when(apiDataExchangeParameter.getCreditLimit(), "5", 3)
                .when(apiDataExchangeParameter.getCreditLimit(), "6", 2)
                .end(0);
        yiRongQianBaoData.setCredit_card(creditCard);
        // 花呗：0 未知；1 无；2 有
        Integer huaBei = ChooseEq.create()
                .when(apiDataExchangeParameter.getHbLimit(), "1", 1)
                .when(apiDataExchangeParameter.getHbLimit(), "2", 2)
                .when(apiDataExchangeParameter.getHbLimit(), "3", 2)
                .when(apiDataExchangeParameter.getHbLimit(), "4", 2)
                .when(apiDataExchangeParameter.getHbLimit(), "5", 2)
                .end(0);
        yiRongQianBaoData.setHuabei(huaBei);
        // 京东白条：0 未知；1 无；2 有
        Integer btLimit = ChooseEq.create()
                .when(apiDataExchangeParameter.getBtLimit(), "1", 1)
                .when(apiDataExchangeParameter.getBtLimit(), "2", 2)
                .when(apiDataExchangeParameter.getBtLimit(), "3", 2)
                .when(apiDataExchangeParameter.getBtLimit(), "4", 2)
                .when(apiDataExchangeParameter.getBtLimit(), "5", 2)
                .end(0);
        yiRongQianBaoData.setBaitiao(btLimit);
        // 贷款金额：0 未知；(例：50000)；单位：元
        Integer money = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanAmount(), "1", 30000)
                .when(apiDataExchangeParameter.getLoanAmount(), "2", 50000)
                .when(apiDataExchangeParameter.getLoanAmount(), "3", 100000)
                .when(apiDataExchangeParameter.getLoanAmount(), "4", 200000)
                .end(0);
        yiRongQianBaoData.setMoney(money);
        // 贷款期数：0 未知；1 6；2 12；3 24；4 36；5 60
        Integer loanTerm = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanTerm(), "1", 1)
                .when(apiDataExchangeParameter.getLoanTerm(), "2", 1)
                .when(apiDataExchangeParameter.getLoanTerm(), "3", 2)
                .when(apiDataExchangeParameter.getLoanTerm(), "4", 3)
                .when(apiDataExchangeParameter.getLoanTerm(), "5", 4)
                .when(apiDataExchangeParameter.getLoanTerm(), "6", 5)
                .end(0);
        yiRongQianBaoData.setPeriods(loanTerm);
        // 贷款用途：0 未知；1 消费贷款；2 房抵贷款；3 车抵贷款；4 经营贷款
        Integer loanPurposeChoose = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanPurpose(), "1", 1)
                .when(apiDataExchangeParameter.getLoanPurpose(), "2", 1)
                .when(apiDataExchangeParameter.getLoanPurpose(), "3", 1)
                .when(apiDataExchangeParameter.getLoanPurpose(), "4", 1)
                .when(apiDataExchangeParameter.getLoanPurpose(), "5", 1)
                .when(apiDataExchangeParameter.getLoanPurpose(), "6", 1)
                .end(0);
        yiRongQianBaoData.setLoan_purpose(loanPurposeChoose);
        // 时间戳，单位秒
        Integer time = (int)(System.currentTimeMillis()/1000L);
       //  data加密
        AES aes = AES.createEcb(KEY.getBytes());
        String content = aes.encryptToBase64Str(JsonUtils.toJson(yiRongQianBaoData));
        // 签名
        String signStr = "channel_code=" + CHANNEL_CODE + "&time=" + time + "&content=" + content + "&key=" + KEY;
        Map<String, Object> map = MapUtils.newHashMap(newMap -> {
            newMap.put("channel_code", CHANNEL_CODE);
            newMap.put("content", content);
            newMap.put("time", time);
            newMap.put("sign", MD5.create().digestToHex(signStr));
        });
        return JsonUtils.toJson(map);
    }

    @Override
    public RespPlatformPhoneMd5DataExchange respDataExchange(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return RespPlatformPhoneMd5DataExchange.ofFail();
        }
        if (!Eq.object(jsonObject.getInteger("code"), 1)) {
            return RespPlatformPhoneMd5DataExchange.ofFail();
        }
        String resData = jsonObject.getString("return_data");
        if (ValidParam.isEmpty(resData)) {
            return RespPlatformPhoneMd5DataExchange.ofFail();
        }
        // return_data解密
        AES aes = AES.createEcb(KEY.getBytes());
        String decData = aes.decryptFromBase64Str(resData);
        JSONObject data = JsonUtils.get(decData);
        if(data == null){
            return RespPlatformPhoneMd5DataExchange.ofFail();
        }
        // 产品名称
        String productName = data.getString("product_name");
        // 机构名称
        String companyName = data.getString("company_name");
        // 产品 LOGO
        String logo = data.getString("logo_url");
        // 协议列表
        List<ApiProtocol> protocolList = new ArrayList<>();
        // 获取协议
        JSONArray listProtocolResult = data.getJSONArray("protocol_list");
        IteratorUtils.array(listProtocolResult, (item, index) -> {
            JSONObject protocolObject = listProtocolResult.getJSONObject(index);
            ApiProtocol protocol = new ApiProtocol();
            protocol.setProtocolName(protocolObject.getString("title"));
            protocol.setProtocolUrl(protocolObject.getString("url"));
            protocolList.add(protocol);
        });
        // 结算金额 分润前的金额(单位：元)
        Integer price = data.getInteger("price");

        RespPlatformPhoneMd5DataExchange result = RespPlatformPhoneMd5DataExchange.ofSuc();

        result.setPrice(BigDecimal.valueOf(price));
        result.setProtocolList(protocolList);
        result.setLogoPath(logo);
        result.setDisplayName(companyName);
        result.setProductName(productName);
        return result;
    }

    @Override
    public Object apply(ApiApplyParameter apiApplyParameter) throws Exception {
        ApiPlatApplyYiRongQianBao yiRongQianBaoData = new ApiPlatApplyYiRongQianBao();
        // 扩展
        ApiFieldConverter apiFieldConverter = ApiFieldConverter.create(apiApplyParameter);
        // 手机号码 MD5
        yiRongQianBaoData.setPhone_md5(apiApplyParameter.getPhoneMd5());
        // 手机号码
        yiRongQianBaoData.setPhone(apiApplyParameter.getPhone());
        // 姓名
        yiRongQianBaoData.setName(apiApplyParameter.getUserName());
        // 年龄：0 未知；身份证号码/性别、年龄(2选1)
        yiRongQianBaoData.setAge(apiFieldConverter.getAgeInt());
        // 性别：0 未知；1 男；2 女；身份证号码/性别、年龄(2选1)
        Integer sex = ChooseEq.create()
                .when(apiApplyParameter.getSex(), "0", 1)
                .when(apiApplyParameter.getSex(), "1", 2)
                .when(apiApplyParameter.getSex(), "2", 0)
                .end(0);
        yiRongQianBaoData.setGender(sex);
        // 用户 IP：0 未知；(例：144.144.144.144)
        if (ValidParam.isNotEmpty(apiApplyParameter.getIp())) {
            yiRongQianBaoData.setIp(apiApplyParameter.getIp());
        } else {
            yiRongQianBaoData.setIp("0");
        }
        // 城市名：0 未知；(例：成都市)；城市编码/城市名(2选1)
        yiRongQianBaoData.setAddress_name(apiApplyParameter.getCity());
        // 学历：0 未知；1 本科以下；2 本科及以上
        Integer education = ChooseEq.create()
                .when(apiApplyParameter.getEducationAttainment(), "1", 1)
                .when(apiApplyParameter.getEducationAttainment(), "2", 1)
                .when(apiApplyParameter.getEducationAttainment(), "3", 1)
                .when(apiApplyParameter.getEducationAttainment(), "4", 1)
                .when(apiApplyParameter.getEducationAttainment(), "5", 2)
                .when(apiApplyParameter.getEducationAttainment(), "6", 2)
                .end(0);
        yiRongQianBaoData.setEducation(education);
        // 职业：0 未知；1 自由职业者；2 上班族；3 企业主/个体户；4 公务员/事业/国企
        Integer career = ChooseEq.create()
                .when(apiApplyParameter.getCareer(), "1", 2)
                .when(apiApplyParameter.getCareer(), "2", 1)
                .when(apiApplyParameter.getCareer(), "3", 3)
                .when(apiApplyParameter.getCareer(), "4", 4)
                .when(apiApplyParameter.getCareer(), "5", 3)
                .end(0);
        yiRongQianBaoData.setVocation(career);
        // 信用：0 未知；1 一年内有逾期；2 一年内无逾期；3 从未逾期
        Integer overdue = ChooseEq.create()
                .when(apiApplyParameter.getOverdue(), "1", 3)
                .when(apiApplyParameter.getOverdue(), "2", 1)
                .when(apiApplyParameter.getOverdue(), "3", 2)
                .end(0);
        yiRongQianBaoData.setCredit(overdue);
        // 贷款申请(近1月)：0 未知；1 3 次以上；2 3 次及以内；3 无申请贷款
        yiRongQianBaoData.setLoans(0);
        // 芝麻分：0 未知；1 无；2 600分及以下；3 600-650分；4 650-700分；5 700分以上
        Integer zhima = ChooseEq.create()
                .when(apiApplyParameter.getSesameCredit(), "1", 2)
                .when(apiApplyParameter.getSesameCredit(), "2", 3)
                .when(apiApplyParameter.getSesameCredit(), "3", 4)
                .when(apiApplyParameter.getSesameCredit(), "4", 5)
                .end(0);
        yiRongQianBaoData.setSesame(zhima);
        // 社保：0 未知；1 无本地社保；2 未满6个月；3 6个月及以上
        Integer socialSecurity = ChooseEq.create()
                .when(apiApplyParameter.getSocialSecurity(), "1", 1)
                .when(apiApplyParameter.getSocialSecurity(), "2", 2)
                .when(apiApplyParameter.getSocialSecurity(), "3", 3)
                .when(apiApplyParameter.getSocialSecurity(), "4", 2)
                .end(0);
        yiRongQianBaoData.setSocial(socialSecurity);
        // 公积金：0 未知；1 无本地公积金；2 未满6个月；3 6个月及以上
        Integer providentFund = ChooseEq.create()
                .when(apiApplyParameter.getProvidentFund(), "1", 1)
                .when(apiApplyParameter.getProvidentFund(), "2", 2)
                .when(apiApplyParameter.getProvidentFund(), "3", 3)
                .when(apiApplyParameter.getProvidentFund(), "4", 2)
                .end(0);
        yiRongQianBaoData.setGjj(providentFund);
        // 房产：0 未知；1 无；2 有异地房产；3 有本地房产
        Integer house = ChooseEq.create()
                .when(apiApplyParameter.getRealEstateInfo(), "1", 1)
                .when(apiApplyParameter.getRealEstateInfo(), "2", 3)
                .when(apiApplyParameter.getRealEstateInfo(), "3", 3)
                .when(apiApplyParameter.getRealEstateInfo(), "4", 3)
                .when(apiApplyParameter.getRealEstateInfo(), "5", 3)
                .when(apiApplyParameter.getRealEstateInfo(), "6", 3)
                .end(0);
        yiRongQianBaoData.setRoom(house);
        // 车产：0 未知；1 无；2 有车不可抵押；3 有车可抵押
        Integer vehicle = ChooseEq.create()
                .when(apiApplyParameter.getCarInfo(), "1", 1)
                .when(apiApplyParameter.getCarInfo(), "2", 2)
                .when(apiApplyParameter.getCarInfo(), "3", 3)
                .when(apiApplyParameter.getCarInfo(), "4", 3)
                .end(0);
        yiRongQianBaoData.setCar(vehicle);
        // 保险保单：0 未知；1 无；2 缴纳未满1年；3 缴纳1年以上
        Integer commericalInsurance = ChooseEq.create()
                .when(apiApplyParameter.getInsurancePolicy(), "1", 1)
                .when(apiApplyParameter.getInsurancePolicy(), "2", 2)
                .when(apiApplyParameter.getInsurancePolicy(), "3", 3)
                .when(apiApplyParameter.getInsurancePolicy(), "4", 2)
                .end(0);
        yiRongQianBaoData.setPolicy(commericalInsurance);
        // 信用卡：0 未知；1 无；2 1万元以下；3 1万元及以上
        Integer creditCard = ChooseEq.create()
                .when(apiApplyParameter.getCreditLimit(), "1", 1)
                .when(apiApplyParameter.getCreditLimit(), "2", 2)
                .when(apiApplyParameter.getCreditLimit(), "3", 2)
                .when(apiApplyParameter.getCreditLimit(), "4", 3)
                .when(apiApplyParameter.getCreditLimit(), "5", 3)
                .when(apiApplyParameter.getCreditLimit(), "6", 2)
                .end(0);
        yiRongQianBaoData.setCredit_card(creditCard);
        // 花呗：0 未知；1 无；2 有
        Integer huaBei = ChooseEq.create()
                .when(apiApplyParameter.getHbLimit(), "1", 1)
                .when(apiApplyParameter.getHbLimit(), "2", 2)
                .when(apiApplyParameter.getHbLimit(), "3", 2)
                .when(apiApplyParameter.getHbLimit(), "4", 2)
                .when(apiApplyParameter.getHbLimit(), "5", 2)
                .end(0);
        yiRongQianBaoData.setHuabei(huaBei);
        // 京东白条：0 未知；1 无；2 有
        Integer btLimit = ChooseEq.create()
                .when(apiApplyParameter.getBtLimit(), "1", 1)
                .when(apiApplyParameter.getBtLimit(), "2", 2)
                .when(apiApplyParameter.getBtLimit(), "3", 2)
                .when(apiApplyParameter.getBtLimit(), "4", 2)
                .when(apiApplyParameter.getBtLimit(), "5", 2)
                .end(0);
        yiRongQianBaoData.setBaitiao(btLimit);
        // 贷款金额：0 未知；(例：50000)；单位：元
        Integer money = ChooseEq.create()
                .when(apiApplyParameter.getLoanAmount(), "1", 30000)
                .when(apiApplyParameter.getLoanAmount(), "2", 50000)
                .when(apiApplyParameter.getLoanAmount(), "3", 100000)
                .when(apiApplyParameter.getLoanAmount(), "4", 200000)
                .end(0);
        yiRongQianBaoData.setMoney(money);
        // 贷款期数：0 未知；1 6；2 12；3 24；4 36；5 60
        Integer loanTerm = ChooseEq.create()
                .when(apiApplyParameter.getLoanTerm(), "1", 1)
                .when(apiApplyParameter.getLoanTerm(), "2", 1)
                .when(apiApplyParameter.getLoanTerm(), "3", 2)
                .when(apiApplyParameter.getLoanTerm(), "4", 3)
                .when(apiApplyParameter.getLoanTerm(), "5", 4)
                .when(apiApplyParameter.getLoanTerm(), "6", 5)
                .end(0);
        yiRongQianBaoData.setPeriods(loanTerm);
        // 贷款用途：0 未知；1 消费贷款；2 房抵贷款；3 车抵贷款；4 经营贷款
        Integer loanPurposeChoose = ChooseEq.create()
                .when(apiApplyParameter.getLoanPurpose(), "1", 1)
                .when(apiApplyParameter.getLoanPurpose(), "2", 1)
                .when(apiApplyParameter.getLoanPurpose(), "3", 1)
                .when(apiApplyParameter.getLoanPurpose(), "4", 1)
                .when(apiApplyParameter.getLoanPurpose(), "5", 1)
                .when(apiApplyParameter.getLoanPurpose(), "6", 1)
                .end(0);
        yiRongQianBaoData.setLoan_purpose(loanPurposeChoose);
        // 协议列表
        yiRongQianBaoData.setBc_agreement(CollUtils.newArrayList(newList -> {
            ApiPlatApplyYiRongQianBao.ProtocolList protocolList = new ApiPlatApplyYiRongQianBao.ProtocolList();
            protocolList.setTitle("个人信息授权协议");
            protocolList.setUrl(H5DomainUrlUtils.createUserProtocolUrl(apiApplyParameter.getProductPlanId(), apiApplyParameter.getPhoneMd5()));
            newList.add(protocolList);
        }));
        // 时间戳，单位秒
        Integer time = (int)(System.currentTimeMillis()/1000L);
        //  data加密
        AES aes = AES.createEcb(KEY.getBytes());
        String content = aes.encryptToBase64Str(JsonUtils.toJson(yiRongQianBaoData));
        // 签名
        String signStr = "channel_code=" + CHANNEL_CODE + "&time=" + time + "&content=" + content + "&key=" + KEY;
        Map<String, Object> map = MapUtils.newHashMap(newMap -> {
            newMap.put("channel_code", CHANNEL_CODE);
            newMap.put("content", content);
            newMap.put("time", time);
            newMap.put("sign", MD5.create().digestToHex(signStr));
        });
        return JsonUtils.toJson(map);
    }

    @Override
    public RespPlatformPhoneMd5Apply respApply(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return RespPlatformPhoneMd5Apply.ofFail();
        }
        if (!Eq.object(jsonObject.getInteger("code"), 1)) {
            return RespPlatformPhoneMd5Apply.ofFail();
        }
        return RespPlatformPhoneMd5Apply.ofSuc();
    }

    @Override
    public RespPlatformNoticeApply parseApplyNotice(RequestVO requestVO) {
        return null;
    }

    @Override
    public Map<String, Object> respApplyNotice(ApiBizStatus apiBizStatus) {
        return Map.of();
    }
}
